<link rel="stylesheet" href="/static/admin/css/tagsinput.css">
<script src="/static/admin/editor/examples/js/jquery.min.js"></script>
<script src="/static/admin/js/tagsinput.js" type="text/javascript" charset="utf-8"></script>
<div class="admin-submenu">
    <div style="width: 100%; height: 100%">

        <div class="submenu-scene">
            文章管理
        </div>

        <div class="submenu-item">文章管理</div>

        <ul>
            <li><a href="/article"> 文章管理</a></li>
            <li class="active"><a href="/article/add">添加文章</a></li>
            <li><a href="/article/category">添加标签</a></li>
        </ul>

        <div id="admin-submenu-c">
            <i class="layui-icon layui-icon-prev"></i>
        </div>

    </div>

</div>

<div class="admin-content">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-md12">
            <div class="admin-block">
                <div class="block">
                    <div class="block-tab">
                        <div class="layui-tab layui-tab-brief" lay-filter="fors">
                            <ul class="layui-tab-title">
                                <li class="layui-this">添加文章</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <div class="block-body">
                                        <div class="example">
                                            <form class="layui-form" action="" method="post"
                                                  lay-filter="component-form-element">
                                                <div class="layui-row layui-col-space10 layui-form-item">
                                                    <div class="layui-col-md4">
                                                        <label class="layui-form-label"><span class="text-red">*</span>文章标题：</label>
                                                        <div class="layui-input-block">
                                                            <input type="text" name="title" lay-verify="required"
                                                                   placeholder="" autocomplete="off"
                                                                   class="layui-input">
                                                        </div>
                                                    </div>
                                                    <div class="layui-col-md4">
                                                        <label class="layui-form-label"><span class="text-red">*</span>文章分类：</label>
                                                        <div class="layui-input-block">
                                                            <select name="cid" lay-verify="required" lay-filter="aihao">
                                                                <option value=""></option>
                                                            {{range .list}}
                                                                <option value="{{.Id}}">{{.Name}}</option>{{end}}
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="layui-col-md4 tagsinput-primary form-group">
                                                        <label class="layui-form-label"><span class="text-red">*</span>云标签：</label>
                                                        <div class="layui-input-block">
                                                            <input type="text" name="tags" lay-verify="required"
                                                                   placeholder="输入后回车" autocomplete="off"
                                                                   class="tagsinput" id="tagsinputval"
                                                                   data-role="tagsinput">
                                                        </div>
                                                    </div>

                                                    <div class="layui-col-md4">
                                                        <label class="layui-form-label"><span class="text-red">*</span>作者：</label>
                                                        <div class="layui-input-block">
                                                            <input type="text" name="author" lay-verify="required"
                                                                   placeholder="" autocomplete="off" class="layui-input"
                                                                   value="{{.user}}">
                                                        </div>
                                                    </div>
                                                    <div class="layui-col-md4">
                                                        <label class="layui-form-label"><span class="text-red">*</span>状态：</label>
                                                        <div class="layui-input-block">
                                                            <select name="status" lay-verify="required"
                                                                    lay-filter="aihao">
                                                                <option value="0">0</option>
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="layui-col-md4 tagsinput-primary form-group">
                                                        <label class="layui-form-label">密码：</label>
                                                        <div class="layui-input-block">
                                                            <input type="text" name="password" placeholder="输入后回车"
                                                                   autocomplete="off" class="tagsinput"
                                                                   id="tagsinputval" data-role="tagsinput">
                                                        </div>
                                                    </div>

                                                    <div class="layui-form-item">
                                                        <label class="layui-form-label"><span class="text-red">*</span>摘要：</label>
                                                        <div class="layui-input-block">
                                                            <textarea name="summary" placeholder=""
                                                                      class="layui-textarea"></textarea>
                                                        </div>
                                                    </div>

                                                </div>
                                                <link rel="stylesheet"
                                                      href="/static/admin/editor/examples/css/style.css">
                                                <link rel="stylesheet" href="/static/admin/editor/css/editormd.css">
                                                <div class="layui-form-item">
                                                    <div id="layout layui-form-item">
                                                        <div id="editormd">
                                                            <textarea style="display:none;" id="content"></textarea>
                                                        </div>
                                                    </div>
                                                    <script src="/static/admin/editor/editormd.js"></script>
                                                    <script type="text/javascript">
                                                        var testEditor;
                                                        $(function () {
                                                            testEditor = editormd("editormd", {
                                                                width: "100%",
                                                                height: 750,
                                                                syncScrolling: "single",
                                                                saveHTMLToTextarea: true,
                                                                path: "/static/admin/editor/lib/",
                                                                toolbarIcons: function () {
                                                                    // Or return editormd.toolbarModes[name]; // full, simple, mini
                                                                    // Using "||" set icons align right.
                                                                    //return ["undo", "redo", "bold", "hr", "preview", "watch","fullscreen", "info", "testIcon", "testIcon2", "file", "faicon", "||", "watch", "fullscreen", "preview", "testIcon"]
                                                                    return editormd.toolbarModes["full"];
                                                                },
                                                            });
                                                        });
                                                    </script>

                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-input-block">
                                                        <button class="layui-btn" lay-submit="" lay-filter="submit">
                                                            立即提交
                                                        </button>
                                                        <button type="reset" class="layui-btn layui-btn-primary">重置
                                                        </button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>

                                    </div>

                                </div>
                            </div>

                        </div>

                    </div>


                </div>

            </div>

        </div>

    </div>
</div>

<script>
    layui.use(['jquery', 'layer', 'form'], function () {
        var $ = layui.jquery
                , layer = layui.layer
                , form = layui.form;
        form.on('submit(submit)', function (data) {
            console.log(data);
            //return false;
            $.post("/api/article/add", data.field, function (res) {
                if (res.Error === 0) {
                    layer.open({
                        title: res.Title
                        , content: res.Msg,
                        btn: ['首页', '后台'],
                        yes: function (index) {
                            window.location.href = "/";
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                        }
                        , btn2: function (index) {
                            window.location.href = "/admin";
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                        }
                    });
                } else {
                    layer.msg(res.Title + res.Msg, {time: 2000});
                }
            }, "json");
            return false;
        })
    });
</script>